import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/page/materialSetting/provider/material_setting_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/custom_tab.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'material_list.dart';
import 'material_menu_list.dart';
import 'material_subtitle.dart';

class MaterialBrowser extends StatefulWidget {
  @override
  _MaterialBrowserState createState() => _MaterialBrowserState();
}

class _MaterialBrowserState extends State<MaterialBrowser> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Expanded(
          child: Consumer<MaterialSettingProvider>(
            builder: (context, materialSettingProvider, _) {
              return CustomTab(
                initialIndex: materialSettingProvider.meterialType,
                padding: EdgeInsets.only(
                  top: 15.w,
                ),
                onChanged: (index) {
                  materialSettingProvider.setTabIndex(index);
                },
                isScrollable: false,
                tabs: ['同分类下加料配菜', '同菜品下加料配菜'],
                tabViews: <Widget>[
                  Column(
                    children: <Widget>[
                      MaterialSubtitle(
                        canEdit: false,
                      ),
                      MaterialMenuList(),
                    ],
                  ),
                  Column(
                    children: <Widget>[
                      MaterialSubtitle(
                        canEdit: true,
                      ),
                      MaterialList(),
                    ],
                  ),
                ],
              );
            },
          ),
        ),
        FixedBottomBtn(
          title: '保 存',
          onTap: () {
            var materialSettingProvider = Provider.of<MaterialSettingProvider>(
              context,
              listen: false,
            );

            materialSettingProvider.saveAndPop(context);
          },
        ),
      ],
    );
  }
}
